package org.mspring.mlog.web.module.web.ucenter.admin;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.mspring.mlog.entity.SpaceInfo;
import org.mspring.mlog.service.SpaceInfoService;
import org.mspring.platform.web.freemarker.widget.stereotype.Widget;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 空间设置
 * 
 * @author Gao Youbo
 * @since 2013年7月16日
 */
@Widget
@RequestMapping("/u/{username}/admin/space")
public class UCenterAdmin_SpaceInfoWidget extends Abstract_UCenterAdminWidget {
    @Autowired
    private SpaceInfoService spaceInfoService;

    @RequestMapping("/info")
    public String info(@ModelAttribute SpaceInfo spaceInfo, HttpServletRequest request, HttpServletResponse response, Model model) {
        spaceInfo = spaceInfoService.getByUser(spaceUser.getId());
        if (spaceInfo != null) {
            model.addAttribute("spaceInfo", spaceInfo);
        }
        return "skin:/ucenter/admin/space/info";
    }

    @RequestMapping("/info/do")
    public String info_do(@ModelAttribute SpaceInfo spaceInfo, HttpServletRequest request, HttpServletResponse response, Model model) {
        spaceInfo.setUser(spaceUser.getId());
        spaceInfoService.merge(spaceInfo);
        return String.format("redirect:/u/%s/admin/space/info", spaceUser.getName());
    }

}
